package com.autoai.animation.demo;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

/**
 * @author Wangjw
 * @date 2020-12-17
 * @brief
 */
public class FirstFragment extends Fragment {

    CustomVideoView customVideoView;
    Button change_background;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.lay_first_fragment, container, false);
        customVideoView = view.findViewById(R.id.customVideoView);
        change_background = view.findViewById(R.id.change_background);
        WallpaperControl.getInstance().setCustomVideoView(customVideoView);
        return view;
    }


    @Override
    public void onResume() {
        super.onResume();
//        WallpaperControl.getInstance().initVideoView();
        change_background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (WallpaperControl.getInstance().isPlaying()) {
                    WallpaperControl.getInstance().stopVideoView();
                } else {
                    WallpaperControl.getInstance().initVideoView();
                }
            }
        });
    }


    @Override
    public void onStop() {
        super.onStop();
        WallpaperControl.getInstance().stopVideoView();
    }


}
